package com.example.demo.model;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张杰
 * Date: 2022-08-07
 * Time: 10:01
 */
@RestController
public class TestController {
    @RequestMapping("/sayhi")
    public String sayHi() {
        return "222";
    }

    @RequestMapping("/fw")
    public String myForward() {
        return "forword:/hello.html";
    }

    @RequestMapping("/fw2")
    public void myForward2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/hello.html").forward(request,response);
    }

    @RequestMapping("/rd")
    public String myRedirect() {
        return "redirect:/hello.html";
    }

    @RequestMapping("/rd2")
    public void myRedirect2(HttpServletResponse response) throws IOException {
        response.sendRedirect("/hello.html");
    }

}
